package org.redis.cluster.transport.netty.test;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redis.cluster.RedisCluster;
import org.redis.cluster.config.DefaultConfigManager;
import org.redis.cluster.config.ConfigManager;
import org.redis.cluster.config.ServerConfig;
import org.redis.cluster.config.SystemConfig;
import org.redis.cluster.redis.transport.codec.server.RedisServerProtocolDecoder;
import org.redis.cluster.test.TestRedisCluster;
import org.redis.cluster.transport.netty.server.NettyServer;
import org.redis.cluster.transport.support.ByteProtocolEncoder;

import redis.clients.jedis.Jedis;

public class NettyTester_1 {
	
	private NettyServer server;

	@Before
	public void before() {
		this.server=initServer();
	}
	
	protected NettyServer initServer() {
		ServerConfig serverConfig=new ServerConfig();
		serverConfig.setServer("test");
		serverConfig.setHost("test");
		serverConfig.setPort(6379);
		serverConfig.setThread(1);
		serverConfig.setBufferSize(1024*10);
		serverConfig.setTimeout(1000*3);
		ConfigManager configManager=new DefaultConfigManager(serverConfig, null, new SystemConfig(null));
		RedisCluster redisCluster=new TestRedisCluster(configManager);
		
		NettyServer server=new NettyServer(configManager.getServerConfig(), new RedisServerProtocolDecoder(), new ByteProtocolEncoder(), new TestProcessor_1());
		server.init(redisCluster);
		return server;
	}
	
	@Test
	public void test() throws Exception {
		server.startup();
		
		Jedis jedis=new Jedis("127.0.0.1",6379,1000*60);
//		Assert.assertEquals("PONG", jedis.ping());
//		
		for(int i=0;i<1000;i++) {
			Assert.assertEquals("OK", jedis.set(RandomStringUtils.randomAlphabetic(10000), RandomStringUtils.randomAlphabetic(100)));
		}
	}
}